package com.lan.util;

import com.lan.model.Clazz;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class ImportContext {

    private Map<String, String> strMap = new HashMap<>();

    private Map<String, Clazz> classMap = new HashMap<>();


    public ImportContext() {
    }

    public void put(String key, String value) {
        strMap.put(key, value);
    }

    public String get(String key) {
        return strMap.get(key);
    }


    public Clazz getClazz(String key) throws ClassNotFoundException {
        Clazz clzz = classMap.get(key);
        if (clzz == null) {
            synchronized (this) {
                String className = get(key);
                if (className != null) {
                    Class<?> cls = Class.forName(className);
                    clzz = new Clazz(cls);
                    classMap.put(key, clzz);
                }
            }
        }
        return clzz;
    }
}
